package com.sofwin.configer;

import org.apache.commons.io.filefilter.DelegateFileFilter;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

/**
 * @packageName: com.sofwin.configer
 * @user: andyliu
 * @date: 2021/12/13 15:09
 * @email 115176513@qq.com
 * @description: TODO
 */

public class WebApp extends AbstractAnnotationConfigDispatcherServletInitializer {
    /**
     * 基础的配置类
     * @return
     */
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{RootConfiger.class};
    }

    /**
     * mvc配置类
     * @return
     */
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{MvcConfiger.class};
    }

    /**
     * url-pattern
     * @return
     */
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        super.onStartup(servletContext);
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("utf-8");
        characterEncodingFilter.setForceRequestEncoding(true);
        servletContext.addFilter("characterEncoding",characterEncodingFilter).addMappingForUrlPatterns(null,true,"/*");

        DelegatingFilterProxy delegatingFilterProxy = new DelegatingFilterProxy();
        servletContext.addFilter("shiroFilter",delegatingFilterProxy).addMappingForUrlPatterns(null,true,"/*");
        // 定义servlet

        // 定义监听器
    }
}
